package com.nextive.weightlogger.dto;

import com.nextive.weightlogger.WeightUnit;

/**
 * Data transfer object representing the user settings for this application.
 * 
 * @author Federico Baseggio <fedebaseggio@gmail.com>
 */
public class Settings {
	/**
	 * The RecipientType specifies the type of recipient for user shares by
	 * default.
	 * 
	 * @author Federico Baseggio <fedebaseggio@gmail.com>
	 */
	public static enum RecipientType
	{
		/**
		 * Indicates that the default recipient is the user himself.
		 */
		SELF,

		/**
		 * Indicates that the default recipient is a contact specified through
		 * {@link Settings#setDefaultRecipientEmail(String)}.
		 */
		CONTACT;
	}
	
	/**
	 * The name of the user.
	 */
	private String name;
	
	/**
	 * The user's email address.
	 */
	private String email;
	
	/**
	 * The type of recipient of the user's shares.
	 */
	private RecipientType defaultRecipientType;
	
	/**
	 * The e-mail address of the default recipient for the user's shares.
	 */
	private String defaultRecipientEmail;
	
	/**
	 * The weight unit used for display and user inputs.
	 */
	private WeightUnit unit;
	
	/**
	 * Constructor.
	 */
	public Settings() {
	}

	/**
	 * Gets the name of the user.
	 * 
	 * @return The name of the user.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Sets the name of the user.
	 * 
	 * @param name The name of the user.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Gets the user's email address.
	 * 
	 * @return The user's email address.
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * Sets the user's email address.
	 * 
	 * @param email The user's email address.
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * Gets the type of default recipient.
	 * 
	 * @return The type of default recipient.
	 */
	public RecipientType getDefaultRecipientType() {
		return defaultRecipientType;
	}

	/**
	 * Sets the type of default recipient. Setting it to
	 * {@link RecipientType#SELF} will make {@link #getDefaultRecipientEmail()}
	 * return the user's e-mail address just like {@link #getEmail()}.
	 * 
	 * @param defaultRecipientType
	 *            The type of default recipient.
	 */
	public void setDefaultRecipientType(RecipientType defaultRecipientType) {
		this.defaultRecipientType = defaultRecipientType;
	}

	/**
	 * Gets the e-mail address of the default recipient for the
	 * user's shares. If {@link #defaultRecipientType} is
	 * {@link RecipientType#SELF} then this method will return
	 * the user's own e-mail address.
	 * 
	 * @return The default recipient's e-mail address.
	 */
	public String getDefaultRecipientEmail() {
		if (defaultRecipientType == RecipientType.SELF)
		{
			return getEmail();
		}
		return defaultRecipientEmail;
	}

	/**
	 * Sets the e-mail address of the default recipient for the user's shares.
	 * 
	 * @param defaultRecipientEmail The default recipient's e-mail address.
	 */
	public void setDefaultRecipientEmail(String defaultRecipientEmail) {
		this.defaultRecipientEmail = defaultRecipientEmail;
	}

	/**
	 * Gets the weight unit used for display and user inputs.
	 * 
	 * @return The weight unit used for display and user inputs.
	 */
	public WeightUnit getUnit() {
		return unit;
	}

	/**
	 * Sets the weight unit used for display and user inputs.
	 * 
	 * @param unit The weight unit used for display and user inputs.
	 */
	public void setUnit(WeightUnit unit) {
		this.unit = unit;
	}
}
